package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
* 统一异常处理
* */
@ControllerAdvice
public class CommonExceptionHandler {

    /*
    * 捕获自定义异常信息
    *
    * */
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object HandlerLogic(Exception e){

        /*打印异常信息*/
        e.printStackTrace();
       return new JsonResult<>(JsonResult.CODE_ERROR_PARAM, e.getMessage(), null);
    }



    /*
     * 捕获运行时异常信息
     *（系统异常信息）
     * */
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object HandlerRuntime(Exception e){
        /*打印异常信息*/
        e.printStackTrace();
        return JsonResult.defaultError();
    }
}
